<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:5px;">
    <div class="layui-tab">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">显示方式：</label>
                        <div class="layui-input-block">
                            <input type="radio"  name="type" lay-filter="type" class="layui-input" value="1"  title="部门" checked>
                            <input type="radio"  name="type" lay-filter="type" class="layui-input" value="2"  title="年级">
                            <input type="radio"  name="type" lay-filter="type" class="layui-input" value="3"  title="科目">
                        </div>
                    </div>
                    <input type="hidden"  name="campus_id" id="campus_id">
                    <input type="hidden"  name="department_id" id="department_id">
                    <div class="layui-tab-content bm">
                        <div class="layui-collapse">
                            <div class="layui-colla-item">
                                <div class="layui-colla-item">
                                    <h2 class="layui-colla-title">校务助手</h2>
                                    <div class="layui-colla-content layui-show">
                                        <div class="layui-collapse" lay-accordion="">
                                            {volist name="campus" id="v"}
                                            <div class="layui-colla-item">
                                                <h2 class="layui-colla-title" onclick="campus(this,{$v.id})">
                                                    <span>{$v.campus_name}</span></h2>
                                                <div class="layui-colla-content">
                                                    <div style="margin-bottom: 10px;" id="{$v.id}">
                                                    </div>
                                                    <div class="layui-collapse" lay-accordion="">
                                                        {volist name="$teacher_data_department" id="d"}
                                                        <div class="layui-colla-item">
                                                            <h2 class="layui-colla-title"  onclick="department(this,{$d.department_id})">
                                                                <span>{$d['teacher_department']}</span>
                                                            </h2>
                                                            <div class="layui-colla-content">
                                                                <div id="department{$d.department_id}">
                                                                </div>
                                                            </div>
                                                        </div>
                                                        {/volist}
                                                    </div>
                                                </div>
                                            </div>
                                            {/volist}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-content nj">
                        <div class="layui-collapse">
                            <div class="layui-colla-item">
                                <div class="layui-colla-item">
                                    <h2 class="layui-colla-title">校务助手</h2>
                                    <div class="layui-colla-content layui-show">
                                        <div class="layui-collapse" lay-accordion="">
                                            {volist name="teacher_data_grades" id="g"}
                                            <div class="layui-colla-item">
                                                <h2 class="layui-colla-title"  onclick="grade(this,{$g.grade_id})">
                                                    <span>{$g['teacher_grade']}</span>
                                                </h2>
                                                <div class="layui-colla-content">
                                                    <div id="grade{$g.grade_id}">
                                                    </div>
                                                </div>
                                            </div>
                                            {/volist}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-content km">
                        <div class="layui-collapse">
                            <div class="layui-colla-item">
                                <div class="layui-colla-item">
                                    <h2 class="layui-colla-title">校务助手</h2>
                                    <div class="layui-colla-content layui-show">
                                        <div class="layui-collapse" lay-accordion="">
                                            {volist name="teacher_data_subject" id="s"}
                                            <div class="layui-colla-item">
                                                <h2 class="layui-colla-title"  onclick="subject(this,{$s.subject_id})">
                                                    <span>{$s['teacher_subject']}</span>
                                                </h2>
                                                <div class="layui-colla-content">
                                                    <div id="subject{$s.subject_id}">
                                                    </div>
                                                </div>
                                            </div>
                                            {/volist}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>
</div>

<div style=" position:fixed; left:2px; bottom:2px; right:2px; width:100%; background-color:rgba(0,0,0,0.5); height:50px; z-index:9999;">
    <form class="layui-form">
        <div class="layui-form-item" style="text-align: center;margin-top:5px;">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="teacher" placeholder="已选择老师" readonly id="teacher" autocomplete="off" placeholder=""
                           class="layui-input">
                    <input type="hidden" id="assistant_id" name="assistant_id">
                </div>
            </div>
            <div class="layui-inline" style="margin-left: 70px;">
                <div class="layui-input-inline">
                    <a class="layui-btn layui-btn-normal" lay-submit lay-filter="form">确认</a>
                    <a class="layui-btn layui-btn-primary" id="cancel">取消</a>
                </div>
            </div>
        </div>
    </form>
</div>

<!--底部公共部分-->
{include file="common/footer" /}

<script>
    var campus_id = "{$campus_id}";
    function campus(obj, id) {
        $.post("{:url('Teacher/getByCampusId')}", {campus_id: id}, function (response) {
            let ehtml = '';
            let data = response.data;
            console.log(data);
            $.each(data, function (index, element) {
                ehtml += '<a href="javascript:void(0);" onclick=clickId(this,"' + element.teacher_name + '","' + element.id + '")>' + element.teacher_name +
                        '</a><br>';
            })
            $("#" + id + "").html(ehtml);
            $("#campus_id").val(id);
        })
    }

    function department(obj, id) {
        $.post("{:url('Teacher/getByDepartmentId')}", {department_id: id,campus_id:campus_id}, function (response) {
            let ehtml = '';
            let data = response.data;
            console.log(data);
            $.each(data, function (index, element) {
                console.log(element.teacher_name);
                ehtml += '<a href="javascript:void(0);" onclick=clickId(this,"' + element.teacher_name + '","' + element.id + '")>' + element.teacher_name +
                        '</a><br>';
            })
            $("#department"+ id + "").html(ehtml);
        })
    }

    function grade(obj, id) {
        $.post("{:url('Teacher/getByGradeId')}", {grade_id: id,campus_id:campus_id}, function (response) {
            let ehtml = '';
            let data = response.data;
            console.log(data);
            $.each(data, function (index, element) {
                ehtml += '<a href="javascript:void(0);" onclick=clickId(this,"' + element.teacher_name + '","' + element.id + '")>' + element.teacher_name +
                        '</a><br>';
            })
            $("#grade"+ id + "").html(ehtml);

        })
    }

    function subject(obj, id) {
        $.post("{:url('Teacher/getBySubjectId')}", {subject_id: id,campus_id:campus_id}, function (response) {
            let ehtml = '';
            let data = response.data;
            console.log(data);
            $.each(data, function (index, element) {
                ehtml += '<a href="javascript:void(0);" onclick=clickId(this,"' + element.teacher_name + '","' + element.id + '")>' + element.teacher_name +
                        '</a><br>';
            })
            $("#subject"+ id + "").html(ehtml);

        })
    }

    function clickId(obj, teacher_name, id) {
        $("#teacher").val(teacher_name);
        $("#assistant_id").val(id);
    }
    layui.use(['jquery', 'form','element', 'layer'], function () {
        let $ = layui.jquery,
            layer = layui.layer,
            element = layui.element,
            form = layui.form;

        $("#cancel").click(function () {
            let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        })

        $(".nj").hide();
        $(".km").hide();
        form.on('radio(type)', function (data) {
            console.log(data);
            let type = data.value;
            console.log(type);
            if (type == 1) {
                $(".bm").show();
                $(".nj").hide();
                $(".km").hide();
            } else if (type == 2) {
                $(".bm").hide();
                $(".nj").show();
                $(".km").hide();
            } else if (type == 3) {
                $(".bm").hide();
                $(".nj").hide();
                $(".km").show();
            }
        })

        //监听提交
        form.on('submit(form)', function (data) {
            newData = data.field;
            parent.zhujiao(data); //这是父页面函数
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
    });
</script>
